use std::collections::{HashMap, HashSet};

struct Solution {}

fn main() {}

impl Solution {
    pub fn is_isomorphic(s: String, t: String) -> bool {
        let mut char_hash: HashMap<char, char> = HashMap::new();
        let mut used_char: HashSet<char> = HashSet::new();
        let s_iter = s.chars();
        let t_iter = t.chars();
        for idx in 0..s.len() {
            let x = s_iter.clone().nth(idx).unwrap();
            let y = t_iter.clone().nth(idx).unwrap();
            if !char_hash.contains_key(&x) {
                char_hash.insert(x, y);
                if used_char.contains(&y) {
                    return false;
                }
                used_char.insert(y);
            }
            if char_hash.contains_key(&x) {
                if *char_hash.get(&x).unwrap() != y {
                    return false;
                }
            }
        }
        true
    }
}